<?php 
include_once(''.P.'/public/header.html');
?>

<script type="text/javascript" src="res/bootstrapplugin/jquery-bootstable.js"></script>



<style>
.caidan{padding:10px;text-align:left;border-bottom:1px #eeeeee solid;cursor:pointer}
.caidan:hover{background-color:rgba(0,0,0,0.05)}
.caidan.active{background-color:rgba(0,0,0,0.06)}
</style>
</head>

<body>

<?php 
include_once(''.P.'/public/top_manage.html');
?>

<div align="center">

<div style="width:<?=$maxwidth?>;margin:20px 0px" align="left">
	<div style="color:#cccccc">
		<a href="?d=manage&cnum=<?=$cnum?>" class="zhu"><?=lang('manage.home')?></a> &gt;
		<a href="" class="zhu"><?=lang('manage.chattitle')?></a>
	</div>
	
	<div class="mainbody">
	
	<table width="100%">
	<tr valign="top">
	<td style="background:#f9f9f9;min-height:500px;border-right:1px #f1f1f1 solid">
	<div style="width:150px;min-height:500px;">
		
		<div class="caidan<?php if(isempt($type))echo ' active';?>">◇ <a href="?d=manage&cnum=<?=$cnum?>&m=chat">会话列表</a></div>
		
		<div class="caidan<?php if($type=='record')echo ' active';?>">◇ <a href="?d=manage&cnum=<?=$cnum?>&m=chat&type=record">会话记录</a></div>
		
		
	</div>
	</td>
	
	<td width="90%">
	
	<?php if(isempt($type)){?>
<script type="text/javascript" src="res/js/jquery-changeuser.js"></script>		
<script>
function initbody(){
	deleterecordurl = '?m=chat&d=manage&cnum='+cnum+'&a=delchat';
	table = $('#viewshow').bootstable({
		url:'index.php?m=chat&d=manage&a=data&cnum='+cnum+'',method:'get',celleditor:true,tablename:'9',
		fanye:false,cellurl:'index.php?a=savecell',
		columns:[{
			text:'头像',dataIndex:'picurl',renderer:function(v){
				if(!v)v='images/group.png';
				if(v)v='<img src="'+v+'" width="30">';
				return v;
			}
		},{
			text:'会话名',dataIndex:'name',editor:true
		},{
			text:'编号',dataIndex:'num'
		},{
			text:'状态',dataIndex:'status',sortable:true,type:'checkbox',editor:true
		},{
			text:'ID',dataIndex:'id'
		},{
			text:'创建人',dataIndex:'createname'
		},{
			text:'会话里人',dataIndex:'recename'
		},{
			text:'排序号',dataIndex:'sort',sortable:true,type:'number',editor:true,textmsg:'越小越靠前'
		},{
			text:'人员数',dataIndex:'renshu',sortable:true,renderer:function(v,d){
				return ''+v+'&nbsp;<a title="查看人员" onclick="viewkuser('+d.id+')" href="javascript:;"><i class="icon-user"></i></a>&nbsp;<a title="刷新人员" href="javascript:;" onclick="reloaduser('+d.id+')"><i class="icon-refresh"></i></a>';
			}
		},{
			text:'',dataIndex:'opts',align:'left',renderer:function(s,d){
				var str = '<a class="zhu" title="编辑" href="?m=chat&d=manage&cnum='+cnum+'&a=form&id='+d.id+'">编辑</a>&nbsp;';
				if(!d.receid)str += '<a class="zhu" title="加人员" onclick="addusers('+d.id+')"><i class="icon-plus"></i></a>&nbsp;';
				str+='<a class="zhu" title="删除" href="javascript:;" onclick="deleterecord('+d.id+',deleterecordurl,false)"><i class="icon-trash"></i></a>';
				return str;
			}
		}]
	});
}

function addusers(id){
	js.changeuser('','deptusercheck','选人加入会话',{
		onselect:function(sna,sid){
			if(sid){
				js.loading();
				js.ajax({
					url:js.apiurl('chat','addusers'),
					data:{chatid:id,receid:sid},
					type:'post',
					dataType:'json',
					success:function(ret){
						js.msgok('操作成功');
						table.reload();
					}
				});
			}
		}
	});	
}
function reloaduser(id){
	js.loading();
	js.ajax({
		url:js.apiurl('chat','reloaduser'),
		data:{chatid:id},
		dataType:'json',
		success:function(ret){
			js.msgok('操作成功');
			table.reload();
		}
	});	
}

function viewkuser(id){
	js.tanbody('viewshoe','查看人员',500,400,{
		html:'<div id="showviewsuser" align="center" style="height:300px;overflow:auto"><div style="padding:5px"><img src="images/mloading.gif"></div></div>'
	});
	js.ajax({
		url:js.apiurl('chat','getuser'),
		data:{chatid:id},
		dataType:'json',
		success:function(ret){
			viewkusershow(ret.data);
		}
	});	
}
function viewkusershow(ret){
	var a = ret.useraarr,i,len=a.length,s='',oi=0,s1;
	var rs= ret.chatinfo;
	s='<table ><tr>';
	for(i=0;i<len;i++){
		oi++;
		s1='';
		if(!rs.receid)s1='removeuser('+rs.id+','+a[i].id+',this)';
		s+='<td style="padding:10px" onclick="'+s1+'" align="center"><img src="'+a[i].face+'" class="face" style="width:40px;height:40px"><br>';
		if(rs.createid==a[i].id)s+='<font color="#ff6600"><i title="创建者" class="icon-user"></i></font>';
		s+=''+a[i].name+'</td>';
		if(oi%6==0)s+='</tr><tr>';
	}
	lengchang = oi;
	s+='</tr></table>';
	$('#msgview_viewshoe').html('共'+oi+'人');
	$('#showviewsuser').html(s);
}
function removeuser(gid,aid,o1){
	js.confirm('确定要把此人从会话中删除吗？',function(jg){
		if(jg=='yes'){
			$(o1).remove();
			lengchang--;
			$('#msgview_viewshoe').html('共'+lengchang+'人');
			js.ajax({
				url:js.apiurl('chat','removeuser'),
				data:{chatid:gid,aid:aid}
			});	
		}
	});
}

</script>
		
		<div style="padding:10px">
			<div class="blank5"></div>
			<a class="webbtn" href="?d=manage&cnum=<?=$cnum?>&m=chat&a=form">新增</a>
			<div class="blank15"></div>
			<div id="viewshow" style="overflow:auto"></div>			
		</div>

	
	<?php }?>
	
	<?php if($type=='record'){?>
	
	<div style="padding:50px;color:gray">为了保护用户隐私，不会开发此功能。</div>
	
	<?php }?>
	
	<div class="blank10"></div>
	</td>
	</tr>	
	</table>


	</div>
</div>



<?php 
include_once(''.P.'/public/footer.html');
?>
</div>

</body>
</html>